import { defineStore } from 'pinia';
import { ref } from 'vue';

export const useUserStore = defineStore('user', () => {
  const userInfo = ref({
    userId: '1',
    username: '当前用户',
    avatar: ''
  });

  const isLoggedIn = ref(true);

  function setUserInfo(info) {
    userInfo.value = { ...userInfo.value, ...info };
  }

  function logout() {
    isLoggedIn.value = false;
  }

  function login(user) {
    userInfo.value = user;
    isLoggedIn.value = true;
  }

  return {
    userInfo,
    isLoggedIn,
    setUserInfo,
    login,
    logout
  };
}); 